package org.lanqiao.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.lanqiao.entity.RechargeRecord;
import org.lanqiao.service.GiftService;
import org.lanqiao.service.RechargeService;
import org.lanqiao.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("adminRecharge")
@Controller
@ResponseBody
public class RechargeRecordController {

    @Autowired
    private RechargeService rechargeService;

    @Autowired
    private GiftService giftService;
    /**
     * @Author 刘力铭
     * @Date 2019/5/20 17:44
     * @Param []
     * @explain  查询充值流水所有信息及分页功能
     * @return org.lanqiao.entity.RechargeRecord
     */

    @RequestMapping(value = "queryRechargeList")
    public Result queryRechargeList(@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){
        //设置每页显示的数据条数
        PageHelper.startPage(pageNum,5);
        //获取查询到的数据
        Result result = rechargeService.queryRechargeList();
        List data = (List) result.getData();
        //得到分页的结果对象
        PageInfo<RechargeRecord> pageInfo = new PageInfo<RechargeRecord>(data);
        result.setData(pageInfo);
        return result;
    }

    /**
     * @Author 刘力铭
     * @Date 2019/5/20 17:44
     * @Param []
     * @explain  查询用户充值记录
     * @return org.lanqiao.entity.RechargeRecord
     */
    @RequestMapping(value = "selectByName")
   public Result selectByName(String wxName){
        Result result = rechargeService.selectByName(wxName);
        List rlt = (List) result.getData();
        System.out.println(rlt);
        return result;
    }

    @RequestMapping("/wxId/{wxId}")
    public Result getRecords(@PathVariable("wxId") String wxId){
        return Result.ok(giftService.getRecords(wxId));
    }
}
